#include "e2d/imgui/render/Editor.h"
#include "e2d/imgui/Editor.h"
#include "sysx/System.h"

using Editor = e2d::BasicEditor;

template<>
bool Editor::Edit<e2d::CameraView>(const std::string& l, e2d::CameraView& e)
{
    int index = 8;

    if (TreeNode("Projection", e.m_ImguiFlag, index++))
    {
        EditInst<e2d::ProjData>("ProjData", e.m_ProjData);

        TreePop();
    }

    if (TreeNode("ClearConfig", e.m_ImguiFlag, index++))
    {
        ColorInst<glm::vec4>("BgColor", e.m_BackgroundColor);

        CheckBoxInst<bool>("colorBit", e.m_ClearColor);
        CheckBoxInst<bool>("depthStencilBit", e.m_ClearDepthStencil);

        TreePop();
    }

    if (TreeNode("RTT", e.m_ImguiFlag, index++))
    {
        EditInst <e2d::RenderTargetJack>("RTT Out", *e.m_RenderTarget);
        TreePop();
    }


    if (TreeNode("Tools", e.m_ImguiFlag, index++))
    {

    auto cameraViewEdits = e.m_Entity->m_Scene->GetComponentEntitiesMap<e2d::CameraViewEdit>();
    auto cameraViews = e.m_Entity->m_Scene->GetComponentEntitiesMap<e2d::CameraView>();

    std::vector<e2d::EntityMap> cameras;
    cameras.insert(cameras.end(), cameraViewEdits.begin(), cameraViewEdits.end());

    e2d::CustomEditor::ComboEditEntity("source Camera", e.m_SourceCamera, cameras);
    if (ImGui::Button("Copy"))
    {
        if(e.m_SourceCamera)
        {
            e2d::CameraView sourceView;
            if (e.m_SourceCamera.m_Entity->HasComponent<e2d::CameraViewEdit>())
            {
                auto& p = e.m_SourceCamera.m_Entity->GetConst<e2d::CameraViewEdit>();
                //static_cast<e2d::CameraView*>(&p)
                e.CopySource();
            }
        }

    }
    TreePop();
    }


    return false;

}